What is the difference between File.WriteAllText() and File.AppendAllText()?
What is the difference between File.WriteAllText() and File.AppendAllText()?
Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
Anubhav Kumar
19-May-2025The difference between
File.WriteAllText()andFile.AppendAllText()in C# is in how they handle existing file content:File.WriteAllText(path, contents)Example:
If
example.txtalready has data, it will be replaced with"Hello, world!".File.AppendAllText(path, contents)Example:
If
example.txtalready has"Hello, world!", after this call it will contain:Summary
File.WriteAllTextFile.AppendAllText